package com.example.bookstore.service.impl;

import com.example.bookstore.entity.Book;
import com.example.bookstore.entity.Category;
import com.example.bookstore.mapper.BookMapper;
import com.example.bookstore.service.BookService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Resource
    private BookMapper bookMapper;


    @Override
    public List<Book> findAll() {
        List<Book> list = bookMapper.findAll();
        return list;
    }

    @Override
    public List<Category> findAllCategory() {
        List<Category> cList = bookMapper.findAllCategory();
        return cList;
    }

    @Override
    public Book findById(Integer id) {
        Book book = bookMapper.findById(id);
        return book;
    }

    @Override
    public List<Book> findByCategoryId(Integer cid) {
        List<Book> list = bookMapper.findByCategory(cid);
        return list;
    }



    @Override
    public Integer add(Book book) {
        Integer row = bookMapper.add(book);
        return row;
    }

    @Override
    public List<Book> findByKeyWord(String bookName) {
        if(bookName != null &&bookName.length()>0){
            bookName="%"+bookName+"%";
        }
        List<Book> list = bookMapper.findByKeyWord(bookName);
        return list;
    }


}
